package com.wondertek.poms.dao.repo;

import com.wondertek.poms.dao.po.ContentBaseFee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author evan0213
 * @description
 */
@Repository
public interface IContentBaseFeeDao extends JpaRepository<ContentBaseFee, Long> {
	@Query(value = "select * from CONTENT_BASE_FEE where TYPE=2 and POMS_ID=?1", nativeQuery = true)
	List<ContentBaseFee> findByPomsId(Long pomsId);

	@Query(value = "select * from CONTENT_BASE_FEE where TYPE=1 and POMS_ID=?1", nativeQuery = true)
	List<ContentBaseFee> findByPrdInfoId(Long prdInfoId);

	/** TODO
	 *@author gaozhengxing gaozhenghang@wondertek.com.cn
	 *@date 2021/1/5 17:43
	 *@param pomsId type=1:产品包id，type=2：节目id
	 *@param channelPackageId 渠道包ID
	 *@return  产品id,s*/
	@Query(value = "select  listagg(cb.product_id,',') within GROUP (order by cb.product_id) from content_base_fee cb  " +
			" where cb.type = 2  and cb.poms_id = ?1 and cb.channel_package_id = ?2", nativeQuery = true)
	Object findByPomsIdAndChannelPackageId(Long pomsId,Long channelPackageId);

	/** 删除
	 *@author gaozhengxing gaozhenghang@wondertek.com.cn
	 *@date 2021/1/5 17:43
	 * @param pomsId type=1:产品包id，type=2：节目id
	 * @param channelPackageId 渠道包ID*/

	void deleteByPomsIdAndChannelPackageId(Long pomsId, Long channelPackageId);

	/** 删除
	 *@author gaozhengxing gaozhenghang@wondertek.com.cn
	 *@date 2021/1/5 17:43
	 *@param prdContId 节目id
	 *@param channelPackage 渠道包ID
	 *@param equityId 权益id
	 */
	@Query(value = "delete from CONTENT_BASE_FEE fee  where fee.POMS_ID = ?1 and fee.CHANNEL_PACKAGE_ID =?2 and fee.EQUITY_ID = ?3",
			nativeQuery = true)
	@Modifying
	void deleteByPrdContAndChannelPackageAndEquityId(String prdContId, String channelPackage,String equityId);

	@Query(value = "delete from CONTENT_BASE_FEE fee  where fee.POMS_ID = ?1 and fee.CHANNEL_PACKAGE_ID =?2 and fee.PRODUCT_ID = ?3",
			nativeQuery = true)
	@Modifying
	void deleteByPrdContAndChannelPackageAndProductId(String prdContId, String channelPackage,String productId);

}
